package com.draemoncode.weixindb.conventer;


import com.draemoncode.weixindb.domain.B_CMessagePackage;
import com.draemoncode.weixindb.server.CMessagePackage;
import com.draemoncode.weixindb.util.JSONUtil;
import com.draemoncode.weixindb.websocket.UIMessage;

public class CMessagePackageConventer {

    public static UIMessage toUIMessage(CMessagePackage cMessagePackage){
        if(cMessagePackage != null){
            UIMessage uiMessage = new UIMessage();
            uiMessage.setType(MessageTypeConventer.toUIType(cMessagePackage.getType()));
            uiMessage.setPodId(cMessagePackage.getSyncid());
            uiMessage.setCreate_time(cMessagePackage.getCreate_time());
            uiMessage.setMsg(cMessagePackage.getMsg());
            return uiMessage;
        }
        return null;
    }

    public static B_CMessagePackage toB_CMessagePackage(CMessagePackage cMessagePackage){
        if(cMessagePackage != null){
            B_CMessagePackage b_cMessagePackage = new B_CMessagePackage();
            b_cMessagePackage.setCreate_time(cMessagePackage.getCreate_time());
            b_cMessagePackage.setMsg(JSONUtil.toJson(cMessagePackage.getMsg()));
            b_cMessagePackage.setSyncid(cMessagePackage.getSyncid());
            b_cMessagePackage.setType(cMessagePackage.getType());
            return b_cMessagePackage;
        }
        return null;
    }
}
